package mmc.server.shell.ops;

import mmc.server.shell.OperationNotAcceptedException;
import mmc.server.shell.ShellException;

public class MMCClassMember extends Operation{

	public String methodName;
	public ArgumentList argumentList;
	
    public MMCClassMember(String text) throws ShellException {
        super(text = text.trim());
        
        if(text.indexOf('(')!=-1){
        	parseMethod();
        }else{
        	parseFieldName();
        }
    }
    
    protected void parseFieldName() throws ShellException{
    	if(!text.matches("[a-zA-z0-9_]*"))
        	throw new OperationNotAcceptedException(false, text + " is not a valid member name!");
    }
    
    protected void parseMethod() throws ShellException{
    	int nameEnd = text.indexOf('(');
    	
    	methodName = text.substring(0, nameEnd);
    	argumentList = new ArgumentList(text.substring(nameEnd), 0, true);
    }
    
    @Override
    public double execute() {
        return 0;
    }
    
    public static String getDescription(){
    	return formatHelpString("classmember","predefined class member");
    }
    
    public static PriorityType getPriorityType() {
        return PriorityType.VARIABLE;
    }
    
    public boolean isMethod(){
    	return methodName!=null;
    }
}
